/**
 * 
 */
function GameEngine() {
	if(GameEngine.instance) { //单例模式
		return GameEngine.instance;
	}
	this.pipeArray = [];
	GameEngine.instance = this;
}
GameEngine.prototype = {
	init: function() {
		var _this = this;
		this.bgMoveSpeed = 50;
		//初始的跳鸟，开始按钮，背景
		this.initial_bird = $(".initial-bird");
		this.play_button = $(".play-button");
		this.main = $(".main");
		animate_buffer(this.initial_bird, {
			top: 50
		}, 800, "", false);
		eventUtils.addEvent(this.play_button, 'click', function() {
			_this.play_button.style.display = "none";
			_this.initial_bird.style.display = "none";
			clearInterval(_this.initial_bird._interVal); //animate_buffer内部定义的ele的定时器
			_this.start()
		});
		var bg_x = 0;
		this.bgInterval = setInterval(function() {
			_this.main.style.backgroundPositionX = --bg_x + "px";
		}, _this.bgMoveSpeed);
		return this;
	},
	start: function() {
		var _this = this;
		this.bird = new Bird().init();
		this.pipe_produce_interval = setInterval(function() {
			_this.pipeArray.push(new Pipe().init());
		}, 5000);

	},
	stop: function() {
		var _this = this;
		clearInterval(_this.pipe_produce_interval);
		clearInterval(_this.bird.fall_interval);
		_this.bird.forbidJump();
		this.pipeArray.forEach(function(item,index,arr){
			 clearInterval(item.pipes_intervar);
		});
		console.log("gameover");
	}

}